package service;

import dao.RegistryDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import pojo.MedicalAdvice;
import pojo.Patient;
import pojo.Registry;
import pojo.yy;
import util.PageInfo;

import java.util.List;
@Service
public class RegistryServiceImpl implements RegistryService {
    @Autowired
    private RegistryDAO dao;
    @Override
    public PageInfo<Registry> queryByLike(yy y, int pageNum, int pageSize) {
        String hql="from Registry where 1=1 ";
        if(y!=null) {
            if (y.getIdCard() != null && !"".equals(y.getIdCard())) {
                hql += " and  patient.idCard =:idCard ";
            }
            if (y.getName()!= null && !"".equals(y.getName())) {
                hql += " and  department.name =:name ";
            }
            if (y.getUserName() != null && !"".equals(y.getUserName())) {
                hql += " and  sysUsers.userName =:userName ";
            }
            if (y.getStatus() != null && !"".equals(y.getStatus())) {
                hql += " and status  =:status ";
            }
        }
        return dao.queryByLike3(y, hql, pageNum, pageSize);
    }

    @Transactional
    public void addRegistry(Registry registry) {
        dao.save(registry);

    }
   @Transactional
    public void update(Registry registry, Integer status) {
       Registry o = (Registry) dao.queryById(registry.getId());
       o.setStatus(status);
    }
}
